#include<bits/stdc++.h>
using namespace std;
//int n,r[100002],a[100002],ans,all,temp;
int n,r[100002],a[100002],v[100002],ma;
long long ans;
bool fg=1;
int main(){
    freopen("duel.in","r",stdin);
    freopen("duel.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&r[i]);
        if(r[i]>ma)ma=r[i];
        if(r[i]!=1&&r[i]!=2)fg=0;
        //a[r[i]]++;
        //v[i]++;
    }
    /*all=n-a[1];
    for(int i=1;i<n;i++){
        if(v[i+1]>=a[i]){
            ans+=a[i];
            v[i+1]=0;
        }
        else{

        }
        if(all>=a[i]){
            ans+=all;
            break;
        }
        else{
            temp=max(a[i],a[i+1]);
            ans+=a[i];
            all-=temp;
        }
    }
    ans=n-ans;*/
    if(fg==1){
        for(int i=1;i<=n;i++){
            if(r[i]==1)a[1]++;
            else a[2]++;
            ans=min(a[1],a[2]);
        }
    }
    else{
        for(int i=1;i<=n;i++){
            a[r[i]]++;
            v[r[i]]++;
        }
        for(int i=1;i<=ma;i++){
            if(v[i+1]>=a[i]){
                 ans+=a[i];
                 v[i+1]=0;
            }
            else {
                for(int j=i+1;j<=ma;j++){
                    if(v[j]>=a[i]){
                        ans+=a[i];
                        break;
                    }
                    else{
                        a[i]-=v[j];
                        ans+=v[j];
                        v[j]=0;
                    }
                }
            }
        }
    }
    ans=n-ans;
    printf("%lld",ans);
    fclose(stdin);
    fclose(stdout);
    return 0;
}
